#pragma once

#include "IInterface.h"

#include <tchar.h>

class IModule;

class IModuleManager : public IInterface
{
public:
	enum { ID = 'IMod'|'uleM'|'anag'|'er' };

public:
	virtual HRESULT Initialize(LPCTSTR* argv, int argc) = 0;

	virtual HRESULT Finalize() = 0;

	virtual HRESULT AddModule(int mdid, LPCTSTR lpszModulePath, IModule** ppIModule = NULL) = 0;

	virtual HRESULT AddModule(int mdid, IModule* pIModule, HMODULE hModule = NULL) = 0;

	virtual HRESULT GetModule(int mdid, IModule** ppIModule) = 0;

	virtual HRESULT GetModule(uint32 nModuleIndex, IModule** ppIModule) = 0;

	virtual uint32	GetModuleCount(void) = 0;

	virtual HMODULE GetHandle(IModule* pIModule) = 0;

	virtual HRESULT AutoLoadModules(LPCTSTR lpszModulesPath = _T("Modules\\"), LPCTSTR lpszDebugIdentify = _T("_D.dll")) = 0;

	virtual bool PreTranslateMessage(MSG* pMsg) = 0;

public:
	using IInterface::QI;

	template<class Interface>
	inline Interface* QI(int mid)
	{
		IModule* pIModule = NULL;
		GetModule(mid, &pIModule);
		if(pIModule == NULL)
			return NULL;

		return pIModule->QI<Interface>();
	}
};